import VueCookies from 'vue-cookies';
import { userLogin } from '@/api/commonApi'
export default {
    // 开启命名空间（默认为false）
    namespaced: true,
    actions: {
        asyncLogin({ commit }, params) {
            return userLogin(params).then(data => {
                commit('getUserInfo', data)
                return Promise.resolve()
            }).catch(err => { return Promise.reject(err) });
        }
    },
    mutations: {
        getUserInfo(state, value) {
            state.userInfo = value;
            if (state.userInfo.token) {
                state.isLogin = true;
                VueCookies.set('Authorization', state.userInfo.token, 86400)
                VueCookies.set('isLogin', state.isLogin, 86400)
            }
        },
    },
    state: () => ({
        isLogin: false,
        userInfo: {}
    }),
}